<?php
	class FileSystem {
		
		static function dirFiles($dir, $mask, $vr = false, $kr = false) {
			$ret = array();
			if(!($h = opendir($dir)) && $cfg->err) fatal('', 'opendir for \''.$dir.'\' failed');
			
			while (false !== ($entry = @readdir($h))) {
				if (is_file("$dir/$entry") && preg_match($mask, $entry)) {
					$k = $v = $entry;
					if ($vr != false) $v = preg_replace($mask, $vr, $entry);
					if ($kr != false) $k = preg_replace($mask, $kr, $entry);
					$ret[$k] = $v;
				}
			}
			
			return $ret;
		}
		
		static function dirList($dir, $mask, $vr = false, $kr = false) {
			$ret = array();
			if(!($h = opendir($dir)) && $cfg->err) fatal('', 'opendir for \''.$dir.'\' failed');
			
			while (false !== ($entry = @readdir($h))) {
				if (preg_match($mask, $entry)) {
					$k = $v = $entry;
					if ($vr != false) $v = preg_replace($mask, $vr, $entry);
					if ($kr != false) $k = preg_replace($mask, $kr, $entry);
					$ret[$k] = $v;
				}
			}
			
			return $ret;
		}
		
	}
?>